#导入模块
import cv2
#摄像头
cap=cv2.VideoCapture(0)

falg = 1
num = 1

while(cap.isOpened()):#检测是否在开启状态
    ret_flag,Vshow = cap.read()#得到每帧图像
    gary = cv2.cvtColor(Vshow, cv2.COLOR_BGR2GRAY)
    face_detect = cv2.CascadeClassifier('./static/haarcascade/haarcascade_frontalface_default.xml')
    face = face_detect.detectMultiScale(gary)
    for x,y,w,h in face:
        cv2.rectangle(Vshow,(x,y),(x+w,y+h),color=(0,0,255),thickness=2)
        cv2.putText(Vshow, 'person', (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 1.2, (255, 0, 0), 3)

    cv2.imshow("Capture_Test",Vshow)#显示图像
    k = cv2.waitKey(1) & 0xFF#按键判断
    if k == ord('s'):#保存
       cv2.imwrite("./img/"+str(num)+".123"+".jpg",Vshow)
       print("success to save"+str(num)+".jpg")
       print("-------------------")
       num += 1
    elif k == ord(' '):#退出
        break
#释放摄像头
cap.release()
#释放内存
cv2.destroyAllWindows()



# **********
# bilibili：竞赛空间
# 公众号：竞赛空间
# 淘宝：竞赛空间
# **********